package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.sound.midi.Track;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TransferQueue;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album")
@SuppressWarnings({"all"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;

    @Autowired
    private VodService vodService;

    @GuiGuLogin
    @Operation(summary = "上传声音")
    @PostMapping("/trackInfo/uploadTrack")
    public Result<Map<String, String>> uploadTrack(MultipartFile file) {
        Map<String, String> map = vodService.uploadTrack(file);
        return Result.ok(map);
    }

    @GuiGuLogin
    @Operation(summary = "保存声音")
    @PostMapping("/trackInfo/saveTrackInfo")
    public Result saveTrackInfo(@RequestBody TrackInfo trackInfo) {
        trackInfoService.saveTackInfo(trackInfo);
        return Result.ok();
    }

    @GuiGuLogin(required = false)
    @Operation(summary = "获取当前用户声音分页列表")
    @PostMapping("/trackInfo/findUserTrackPage/{page}/{limit}")
    public Result<Page<TrackListVo>> findUserTrackPage(@PathVariable Long page,
                                                       @PathVariable Long limit,
                                                       @RequestBody TrackInfoQuery trackLnfoQuery) {
        Page<TrackListVo> trackListVoPage = new Page(page, limit);
         trackListVoPage = trackInfoService.findUserTrackPage(trackListVoPage, trackLnfoQuery);
        return Result.ok(trackListVoPage);

    }

    @GuiGuLogin(required = false)
    @Operation(summary = "根据声音id回显数据")
    @GetMapping("/trackInfo/getTrackInfo/{id}")
    public Result<TrackInfo> getTrackInfo(@PathVariable Long id){
        TrackInfo trackInfo = trackInfoService.getById(id);
        return  Result.ok(trackInfo);
    }

    @GuiGuLogin
    @Operation(summary = "修改声音信息")
    @PutMapping("/trackInfo/updateTrackInfo/{id}")
    public Result updateTrackInfo(@PathVariable Long id,
                                  @RequestBody TrackInfo trackInfo){

        trackInfoService.updateTrackInfo(id,trackInfo);
        return Result.ok();
    }

    @GuiGuLogin
    @Operation(summary = "删除声音")
    @DeleteMapping("/trackInfo/removeTrackInfo/{id}")
    public  Result removeTrackInfo(@PathVariable Long id){
        trackInfoService.removeTrackInfo(id);
        return Result.ok();
    }

    /**
     * 根据声音ID，获取声音统计信息
     * @param trackId
     * @return
     */
    @Operation(summary = "根据声音ID，获取声音统计信息")
    @GetMapping("/trackInfo/getTrackStatVo/{trackId}")
    public Result<TrackStatVo> getTrackStatVo(@PathVariable Long trackId){
        return Result.ok(trackInfoService.getTrackStatVo(trackId));
    }


    ///api/album/trackInfo/findUserTrackPaidList/{trackId}
    @Operation(summary = "获取用户声音分集购买支付列表")
    @GetMapping("/trackInfo/findUserTrackPaidList/{trackId}")
    @GuiGuLogin
    public Result<List<Map<String, Object>>> findUserTrackPaidList(@PathVariable Long trackId){
        List<Map<String, Object>> map =  trackInfoService.findUserTrackPaidList(trackId);
        return Result.ok(map);
    }

}

